<template>
    <div>

        <el-dialog title="查询" :visible.sync="selectIdentity">

            <el-form ref="dataForm" class="dialog-Backgroundcolor" :model="detailInfo.queryForm" label-position="right"
                label-width="100px">

                <el-row>

                    <el-row>

                        <el-col :span="12">

                            <el-form-item label="姓名" prop="name">

                                <el-input v-model="detailInfo.queryForm.personName" type="text"
                                    @keyup.enter.native="handleSalaryQuery" />

                            </el-form-item>

                        </el-col>

                        <el-col :span="12">

                            <el-form-item label="身份证号" prop="idCard">

                                <el-input v-model="detailInfo.queryForm.idenNo" type="text"
                                    @keyup.enter.native="handleSalaryQuery" />

                            </el-form-item>

                        </el-col>



                    </el-row>



                    <el-button type="primary" style="float:right;" :loading="detailInfo.listLoading"
                        @click="handleSalaryQuery">

                        查询

                    </el-button>

                </el-row>



            </el-form>



        </el-dialog>

        <el-select v-model="listQuery.changeAgency" class="filter-item" clearable placeholder="全部单位"
            :disabled="listLoading" @change="query">

            <el-option v-for="item in changeAgencys" :key="item.code" :label="item.name" :value="item.code" />

        </el-select>
        <el-select v-model="listQuery.isThirteen" class="filter-item" @change="query">
        <!-- <el-option key="" label="全部批次" value="" placeholder="全部批次" /> -->
            <el-option v-for="item in batchs" :key="item.code" :label="item.name" :value="item.code" />
        </el-select>

        <!-- 表格部分

        排序  :default-sort = "{prop: 'agencyCode', order: 'descending'}"

          :sort-orders="{prop: 'agencyCode', orders: ['ascending', 'descending', null]}"

          sort-orders="{prop: 'agencyCode', orders:['ascending', 'descending', null]}"

        -->

        <el-table ref="singalTable" v-loading="listLoading" :data="list"
            :sort-orders="{ prop: 'agencyCode', orders: ['ascending', 'descending', null] }" :stripe="true"
            :summary-method="getSummaries" show-summary fit style="width: 100%;" :height="tableHeight"
            :header-cell-style="{ background: '#eef1f6', color: '#606266' }" @selection-change="handleSelectionChange">

            <template slot="empty">

                <tableEmpty />
            </template>
            <el-table-column type="selection" width="55" align="center" fixed />
            <el-table-column type="index" align="center" width="55" label="序号" fixed />
            <el-table-column v-if="tabPane === 'all'" label="审核状态" align="center" fixed>
                <template slot-scope="{row}">
                    <span>{{ row.verifyStatus | verifyFilter(that) }}</span>
                </template>
            </el-table-column>

            <el-table-column label="工资月份" prop="salaryMonth" align="center" fixed />
            <el-table-column label="批次" align="center" fixed>
                <template slot-scope="{row}">
                    <span>{{ row.isThirteen | isthirteenfilter(that) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="单位编码" align="center" prop="agencyCode" width="110" fixed sortable>
                <template slot-scope="{row}">
                    <span style="float: left">{{ row.agencyCode }}</span>
                </template>
            </el-table-column>
            <el-table-column label="单位名称" align="center" fixed width="220">
                <template slot-scope="{row}">
                    <span style="float: left">{{ row.agencyName }}</span>
                </template>
            </el-table-column>
            <el-table-column label="变动情况" align="center">
                <template slot-scope="{row}">
                    <el-link type="primary" @click="salaryDetail(row)">

                        变动情况</el-link>
                </template>
            </el-table-column>
            <el-table-column label="发放人数" align="center">
                <el-table-column prop="personNum" label="小计" align="center" />
                <el-table-column prop="adminNum" label="在职人员" align="center" width="100" />
                <!-- <el-table-column
          prop="causeNum"
          label="事业人员"
          align="center"
        /> -->
                <el-table-column prop="quitNum" label="离退休人员" align="center" width="100" />
            </el-table-column>
            <el-table-column label="实发工资" align="center">
                <el-table-column prop="realNum" label="小计" align="center" width="140">
                    <template slot-scope="{row}">
                        <!--获取不带后缀的字段名-->

                        <span v-if="row.realNum !== '' && row.realNum !== null" style="float: right">{{
                                Number(row.realNum).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,")
                        }}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="adminReal" label="在职人员" align="center" width="140">
                    <template slot-scope="{row}">
                        <!--获取不带后缀的字段名-->

                        <span style="float: right">{{ Number(row.adminReal).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g,
                                "$1,")
                        }}</span>
                    </template>
                </el-table-column>
                <!-- <el-table-column
          label="事业人员"
          align="center"
          width="140"
        >
<template slot-scope="{row}">
     -->

                <!--获取不带后缀的字段名-->

                <!-- <span style="float: right">{{ Number(row.causeReal).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
</template>
        </el-table-column> -->
                <el-table-column prop="quitReal" label="离退休人员" align="center" width="140">
                    <template slot-scope="{row}">
                        <!--获取不带后缀的字段名-->

                        <span style="float: right">{{ Number(row.quitReal).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g,
                                "$1,")
                        }}</span>
                    </template>
                </el-table-column>
            </el-table-column>
            <el-table-column label="应发工资" align="center">
                <el-table-column prop="shouldNum" label="小计" align="center" width="140">
                    <template slot-scope="{row}">
                        <!--获取不带后缀的字段名-->

                        <span v-if="row.shouldNum !== '' && row.shouldNum !== null" style="float: right">{{
                                Number(row.shouldNum).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,")
                        }}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="adminShould" label="在职人员" align="center" width="140">
                    <template slot-scope="{row}">
                        <!--获取不带后缀的字段名-->

                        <span style="float: right">{{ Number(row.adminShould).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g,
                                "$1,")
                        }}</span>
                    </template>
                </el-table-column>
                <!-- <el-table-column
          label="事业人员"
          align="center"
          width="140"
        >
<template slot-scope="{row}">
     -->

                <!--获取不带后缀的字段名-->

                <!-- <span style="float: right">{{ Number(row.causeShould).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
</template>
        </el-table-column> -->
                <el-table-column prop="quitShould" label="离退休人员" align="center" width="140">
                    <template slot-scope="{row}">
                        <!--获取不带后缀的字段名-->

                        <span style="float: right">{{ Number(row.quitShould).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g,
                                "$1,")
                        }}</span>
                    </template>
                </el-table-column>
            </el-table-column>

        </el-table>
        <!-- 分页 -->
        <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
        <el-dialog :title="title1" :visible.sync="auditFormVisible" width="30%" max-height="500px">
            <el-form ref="auditForm" :model="formData" label-position="right" label-width="120px" size="small">
                <el-row>
                    <el-col>
                        <el-input v-model="formData.auditExplain" type="textarea" :rows="4" maxlength="450" />
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="16" style="text-align: right; margin-top:5%">
                        <el-button type="primary" :loading="saveExplainLoading" @click="saveExplain">
                            确定
                        </el-button>
                    </el-col>
                </el-row>
            </el-form>
        </el-dialog>
        <el-dialog v-dialogDrag title="工资明细" :visible.sync="salaryFormVisible" fullscreen>
            <div>
                <el-row>
                    <el-form label-position="right" label-width="100px">
                        <el-row>
                            <el-col :span="6">
                                <el-form-item label="人员类别：">
                                    <el-select v-model="detailInfo.listQuery.state" class="filter-item" clearable
                                        placeholder="--请选择--" @change="handleSalaryQuery">
                                        <el-option label="全部人员" value="" />
                                        <el-option label="在职人员" value="3" />
                                        <el-option label="离退休人员" value="1" />
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="工资类别：">
                                    <el-select v-model="detailInfo.queryForm.salaryType" class="filter-item" clearable
                                        placeholder="--请选择--" @change="handleSalaryQuery">
                                        <el-option v-for="item in salaryTypes" :key="item.code" :label="item.name"
                                            :value="item.code" />
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="18">
                                <el-button size="small" class="filter-item" style="margin-left: 10px;" type="primary"
                                    @click="changeIdDialogStatus">
                                    查询
                                </el-button>
                                <el-button v-if="tabPane === '1'" size="small" class="filter-item"
                                    style="margin-left: 10px;" type="primary" @click="exportTemplate">
                                    模板导出
                                </el-button>
                                <el-button v-if="tabPane === '1'" size="small" class="filter-item"
                                    style="margin-left: 10px;" type="primary" @click="financialDialogPass">
                                    审核通过
                                </el-button>
                                <el-button v-if="tabPane === '1'" size="small" class="filter-item"
                                    style="margin-left: 10px;" type="primary" @click="financialDialogReject">
                                    退回
                                </el-button>
                                <el-button size="small" class="filter-item" style="margin-left: 10px;" type="primary"
                                    @click="appendixOpen">
                                    附件管理
                                </el-button>
                                <el-button size="small" class="filter-item" style="margin-left: 10px;" type="primary"
                                    @click="getPersonChange">
                                    人员变动情况查询
                                </el-button>
                                <el-switch v-model="zeroShow" active-text="显示为0项" inactive-text="关闭为0项">
                                </el-switch>
                            </el-col>
                        </el-row>
                    </el-form>
                </el-row>
                <el-row>
                    <el-col :span="24" style="padding-top: 10px; padding-bottom: 10px">
                        <div>单位：{{ detailInfo.agencyName }}&nbsp;统发月份：{{ detailInfo.salaryMonth }}</div>
                        <span style="font-size:16px">在编实发合计：{{
                                Number(detailInfo.reallySendSalarySum).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,")
                        }}元</span>
                        <span style="font-size:16px">（其中：在职合计：{{
                                Number(detailInfo.workSalarySum).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,")
                        }}元</span>，
                        <span style="font-size:16px">离退休合计：{{
                                Number(detailInfo.retireSalarySum).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,")
                        }}元）</span>
                        <span style="font-size:16px"
                            :style="{ color: detailInfo.reallySendChangeSum == 0 ? 'black' : 'red' }"> 实发变动合计：{{
                                    Number(detailInfo.reallySendChangeSum).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,")
                            }}元
                            ；</span>
                        <span style="font-size:16px"
                            :style="{ color: detailInfo.shouldSendChangeSum == 0 ? 'black' : 'red' }"> 应发变动合计：{{
                                    Number(detailInfo.shouldSendChangeSum).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,")
                            }}元</span><br>
                        <span style="font-size:16px">在编人员：{{ detailInfo.personTotal }}人</span>
                        <span style="font-size:16px">（其中：在职：{{ detailInfo.workTotal }}人</span>，
                        <span style="font-size:16px">离退休：{{ detailInfo.retireTotal }}人）</span>；
                        <span style="font-size:16px; color: red">单位增员：{{ detailInfo.unitPlusTotal }}人</span>
                        <span style="font-size:16px; color: red">（其中：在职：{{ detailInfo.workPlusTotal }}人</span>，
                        <span style="font-size:16px; color: red">离退休：{{ detailInfo.retirePlusTotal }}人）</span>；
                        <span style="font-size:16px; color: red">单位减员：{{ detailInfo.unitMinusTotal }}人</span>
                        <span style="font-size:16px; color: red">（其中：在职：{{ detailInfo.workMinusTotal }}人</span>，
                        <span style="font-size:16px; color: red">离退休：{{ detailInfo.retireMinusTotal }}人）</span>；
                        <span style="font-size:16px; color: red">工资变动：{{ detailInfo.salaryChangeNum }} 人</span>;
                        <span style="font-size:16px; color: red">人事变动：{{ detailInfo.personUpdateTotal }}
                            人</span>&nbsp;&nbsp;&nbsp;
                    </el-col>
                </el-row>
            </div>
            <div>
                <!-- 表格部分 -->
                <div style=" width: 100%; display: inline-block; vertical-align: top; ">
                    <el-table ref="singalSalaryTable" v-loading="detailInfo.listLoading" :data="detailInfo.list"
                        :stripe="true" :max-height="mxtableHeight" row-key="personId" :default-expand-all='true' fit
                        :header-cell-style="{ background: '#eef1f6', color: '#606266' }" class="salaryTable">
                        <template slot="empty">
                            <tableEmpty />
                        </template>

                        <el-table-column lable="" prop="index" align="center" width="60" fixed />
                        <el-table-column type="selection" width="30" align="center" fixed />
                        <!-- <el-table-column
              label="工资月份"
              align="center"
              fixed
            >
<template slot-scope="{row}">
    <span :style="{ color: row.different === 1&&row.personId.indexOf('noRepeat') == -1  ? 'red':'black' }">{{ row.currentMonth }}</span>
</template>
            </el-table-column>
            <el-table-column
              label="单位"
              align="center"
              min-width="250"
              fixed
            >
<template slot-scope="{row}">
    <span :style="{ color: row.different === 1&&row.personId.indexOf('noRepeat') == -1   ? 'red':'black' }">{{ detailInfo.agencyName }}</span>
</template>
            </el-table-column>
            <el-table-column
              label="科室"
              align="center"
              fixed
            >
<template slot-scope="{row}">
    <span :style="{ color: row.different === 1 ? 'red':'black' }">{{ row.deptId | deptNameFilter(that) }}</span>
</template>
            </el-table-column> -->
                        <el-table-column label="姓名" align="center" fixed>
                            <template slot-scope="{row}">
                                <el-link type="primary" @click="viewInfo(row)">

                                    <span
                                        :style="{ color: row.different === 1 && row.personId.indexOf('noRepeat') == -1 ? 'red' : 'black' }">{{
                                                row.personName
                                        }}</span>

                                </el-link>
                            </template>
                        </el-table-column>
                        <el-table-column label="身份证号" align="center" min-width="170" fixed>
                            <template slot-scope="{row}">
                                <span
                                    :style="{ color: row.different === 1 && row.personId.indexOf('noRepeat') == -1 ? 'red' : 'black' }">{{
                                            row.idenNo
                                    }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column v-for="item in columnNamesZeroList" :key="item"
                            :label="item.split('_')[0] | salaryNameFilter(that)" align="right" min-width="120">
                            <template slot-scope="{row}">
                                <div
                                    :style="{ float: 'right', color: row[item.split('_')[0]] !== row[item.split('_')[0] + '_history'] && row.index !== '合计' && row.index !== '上月合计' && row.index !== '增减合计' && row.personId.indexOf('noRepeat') == -1 ? 'red' : 'black' }">

                                    <span>{{ Number(row[item.split('_')[0]]).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g,
                                            "$1,")
                                    }}</span>

                                </div>
                            </template>

                        </el-table-column>
                    </el-table>
                </div>
            </div>
            <pagination :total="detailInfo.total" :page.sync="detailInfo.listQuery.page"
                :limit.sync="detailInfo.listQuery.limit" @pagination="queryUnitAuditPage" />
        </el-dialog>
        <Enclosure ref="enc" :middle-table-code="2" />
        <PersonSalaryInfoVerify ref="PersonSalaryInfoVerify" />
        <PersonChangeInfo ref="personChangeInfo" />
        <ApprovalProcess ref="app" />
    </div>
</template>
<script>
import {
    queryFinancialAuditPage,
    financialAuditPass,
    financialAuditReject,
    financialAuditRevoke,
    getAddPersonNumByAgencyId,
    selectSalaryChangePersonNum,
    getSalaryDataByAgencyId
} from '@/api/financialAudit/financialAudit'
import {
    auditLog
} from '@/api/salaryReport/financialVerify'
import { queryFinancialAuditSalaryPage } from '@/api/unitSalaryReport/unitAudit'
import {
    querySalaryNameDict,
    queryColumnName,
    outPutSalaryReportList,
    querySubmitReallySendSalarySumAndPersonTotal
} from '@/api/unitSalaryReport/unitSalaryReport'
import { getDepartmentList } from '@/api/unitInformationMaintenance/internalOrganizationMaintenance'
// 分页
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import tableEmpty from '@/components/table/empty'
import Enclosure from '@/components/Enclosure'
import PersonSalaryInfoVerify from '@/components/personSalaryInfo/personSalaryInfoVerify'
import PersonChangeInfo from '@/components/personChangeInfo/personChangeInfo'
import ApprovalProcess from '@/components/ApprovalProcess/ApprovalProcess'
import { getSalaryType, getIsThirteen } from '@/api/baseInfo'
export default {
    name: 'Unit',
    components: { ApprovalProcess, Pagination, tableEmpty, Enclosure, PersonSalaryInfoVerify, PersonChangeInfo },
    filters: {
        deptNameFilter(value, that) {
            const deptNames = that.detailInfo.deptNames
            for (const item of deptNames) {
                if (value === item.code) {
                    return item.name
                }
            }
        },
        // 工资项滤器
        salaryNameFilter(value, that) {
            const salaryNames = that.detailInfo.salaryNames
            for (const item of salaryNames) {
                if (item.value === value) {
                    return item.key
                }
            }
        },
        verifyFilter(value, that) {
            if (value === '0') {
                return '未审核'
            }
            return value
        },
        isthirteenfilter(value, that) {
            if (value === 0) {
                return '每月工资'
            }
            return "第" + (value + 1) + "批次工资"
        },
        //号码脱敏显示
        hideMiddle(val) {
            if (val !== undefined && val !== null) { //避免列表中存在空数据报错
                return `${val.substring(0, 4)}****${val.substring(val.length - 4)}`
            } else {
                return val
            }
        }
    },
    props: ['tabPane', 'treeData'],
    data() {
        return {
            zeroShow: false,
            tableHeight: null,
            mxtableHeight: null,
            dialogEditFormVisible: false,
            selectIdentity: false,
            dialogStatus: '',
            formStatus: '',
            registerFormVisible: false,
            quitFormVisible: true,

            that: this,
            list: [],
            total: 0,
            listLoading: true,
            selected_list: [],
            listQuery: {
                page: 1,
                limit: 500,
                flag: 'all',
                agencyId: '0',
                isThirteen: '0',
                changeAgency: '',
                salaryType: '',
                menuid: this.$router.currentRoute.meta.menuid,

            },
            batchs: [],
            salaryFormVisible: false,
            title1: '',
            auditFormVisible: false,
            saveExplainLoading: false,
            operateCode: '',
            formData: {
                auditExplain: ''
            },
            detailInfo: {
                list: [],
                total: 0,
                listLoading: false,
                agencyName: '',
                salaryNames: [],
                deptNames: [],
                columnNames: [],
                zeroNames: [],
                salaryMonth: '',
                reallySendChangeSum: '0.00',
                shouldSendChangeSum: '0.00',
                reallySendSalarySum: '0.00',
                workSalarySum: '0.00',
                retireSalarySum: '0.00',
                personTotal: '0',
                workTotal: '0',
                retireTotal: '0',
                unitMinusTotal: '0',
                unitPlusTotal: '0',
                retireMinusTotal: '0',
                workMinusTotal: '0',
                retirePlusTotal: '0',
                workPlusTotal: '0',
                personUpdateTotal: '0',
                tableData: [],
                listQuery: {
                    page: 1,
                    limit: 200,
                    flag: 'all',
                    agencyId: '',
                    state: '',
                    salaryType: '',
                    isThirteen: '',
                    bizKey: '',
                },
                queryForm: {
                    salaryType: '',
                    personName: '',
                    idenNo: ''
                },
                addNum: '0',
                salaryChangeNum: '0',
                operateRows: []
            },
            changeAgencys: [
                { code: '1', name: '有变动单位' },
                { code: '0', name: '无变动单位' }
            ],
            isThirteens: [],//批次
            salaryTypes: [
                { code: '0', name: '行政人员' },
                { code: '1', name: '事业人员' },
                { code: '11', name: '离退休人员' }
            ],
            salarys: [],
            operateAgencyIds: [], // 操作单位id集合
            bizKeys: [], // 操作单位id集合
            bizKey: '',
        }
    },
    watch: {
        zeroShow(val) {
            if (val) {

            }
        },
        list(val) {
            this.doLayout()
        }
    },
    computed: {
        columnNamesZeroList: function () {
            let that = this
            if (this.zeroShow) {
                return this.detailInfo.columnNames
            } else {
                var columnNamesList = that.detailInfo.columnNames;
                if (that.detailInfo.list[0] !== undefined) {
                    return columnNamesList.filter(function (item) {
                        if (that.detailInfo.list[0][item.split('_')[0]] != 0) {
                            return item
                        }
                    })
                } else {
                    return this.detailInfo.columnNames
                }
            }
        }
    },
    // 加载后运行
    created() {
        // 获取参数
        this.listQuery.flag = this.tabPane
        if (this.treeData !== '') {
            this.listQuery.agencyId = this.treeData.id
        }
        // 加载获取全部数据
        this.getList()
        this.initBaseInfo()
    },
    mounted() {
        this.getTbHeight()
    },
    beforeMount() {
        window.addEventListener('resize', this.getTbHeight)
    },
    methods: {

        initBaseInfo() {
            //获取批次信息
            getIsThirteen().then(res => {
                let arr = [];
                res.data.forEach(item => {
                    if (item == 0) {

                        arr.push({
                            code: item,
                            name: "每月工资"
                        });
                    } else {
                        arr.push({
                            code: item,
                            name: "第" + item + "批次"
                        });
                    }
                })
                this.batchs = arr
            })

        },
        // 审核日志
        processnode() {

            const selection = this.$refs.singalTable.selection
            if (selection.length !== 1) {
                let message = '未选择数据，请选择后查看！'
                if (selection.length > 1) {
                    message = '您选择了多条数据，请选择单条数据查看！'
                }
                this.$message({
                    showClose: true,
                    message: message,
                    type: 'warning',
                    duration: 4000
                })
                return
            }
            selection[0].month = selection[0].salaryMonth
            selection[0].agencyId = selection[0].id

            auditLog(selection[0]).then(res => {
                this.$refs.app.getList(res.data)
            })
        },
        /* 重新渲染table组件 */
        doLayout() {
            this.$nextTick(() => {
                this.$refs.singalTable.doLayout()
            })
        },
        // 获取table高度的方法
        getTbHeight() {
            this.tableHeight = window.innerHeight - 270
            this.mxtableHeight = window.innerHeight - 250
        },

        getList() {
            queryFinancialAuditPage(this.listQuery).then(response => {
                this.list = response.data.rows
                this.total = response.data.total
                // this.listQuery.jyfukyf = batch
                this.listLoading = false
                // this.changeTabe()
                this.bizKeys=[]
                // this.setInitRow()

            })
        },
        // 查询
        handleQuery() {
            this.dialogStatus = '查询'
            this.listQuery.page = 1
            // this.listQuery.limit = 10
            this.getList()
            this.dialogEditFormVisible = false
        },
        // 树的点击事件
        handleTree(data) {
            this.listQuery.agencyId = data.id
            this.getList()
        },
        // 切换页签
        changeTabe() {
            this.listQuery.agencyId = '0'
        },
        // 设置工资列表初始选择
        // setInitRow() {
        //     if (this.tabPane === '1') {
        //         this.$refs.singalTable.setCurrentRow(this.list[1])
        //     }
        // },
        // 审核打开页面
        auditPass() {

            this.operateAgencyIds = []
            const selection = this.$refs.singalTable.selection
            if (selection.length === 0) {
                this.$message({
                    message: '请选择要审核的单位',
                    type: 'warning',
                    showClose: true,
                    duration: 4000
                })
                return
            }
            selection.forEach(item => {
                this.operateAgencyIds.push(item.id)
                this.bizKeys.push(item.bizKey)
            })
            this.operateCode = 'audit'
            this.formData = Object.assign({}, this.formData, '')//复制对象{this.formData}
            this.formData.auditExplain = '同意'
            this.title1 = '审核说明'
            this.auditFormVisible = true
        },
        // 退回
        auditReject() {
            this.operateAgencyIds = []
            const selection = this.$refs.singalTable.selection
            if (selection.length === 0) {
                this.$message({
                    message: '请选择要退回的单位',
                    type: 'warning',
                    showClose: true,
                    duration: 4000
                })
                return
            }

            selection.forEach(item => {
                this.operateAgencyIds.push(item.id)
                this.bizKeys.push(item.bizKey)
            })
            this.operateCode = 'reject'
            this.formData = Object.assign({}, this.formData, '')
            if (selection.length === 1) {//如果选择一条数据
                const auditExplain = selection[0].auditExplain  //默认为同意
                this.formData.auditExplain = auditExplain === null ? '不同意' : auditExplain.substring(auditExplain.indexOf('：') + 1)
            } else {
                this.formData.auditExplain = '不同意'
            }
            this.title1 = '退回说明'

            this.auditFormVisible = true
        },
        // 撤销
        auditRevoke() {
            this.operateAgencyIds = []
            const selection = this.$refs.singalTable.selection
            if (selection.length === 0) {
                this.$message({
                    message: '请选择要撤销审核的单位',
                    type: 'warning',
                    showClose: true,
                    duration: 4000
                })
                return
            }
            selection.forEach(item => {
                this.operateAgencyIds.push(item.id)
                this.bizKeys.push(item.bizKey)
            })
            this.operateCode = 'revoke'
            this.formData = Object.assign({}, this.formData, '')
            this.title1 = '撤销说明'
            this.auditFormVisible = true
        },
        // 统一保存
        saveExplain() {
            this.saveExplainLoading = true
            // 审核通过
            if (this.operateCode === 'audit') {
                this.financialAuditPass()
            } else if (this.operateCode === 'reject') {
                // 退回
                this.financialAuditReject()
            } else if (this.operateCode === 'revoke') {
                // 撤销
                this.financialAuditRevoke()
            }
        },
        // 工资明细页面审核通过
        financialDialogPass() {
            this.operateAgencyIds = []
            this.title1 = '审核说明'
            this.auditFormVisible = true
            this.operateCode = 'audit'
            this.formData.auditExplain = '同意'
            this.operateAgencyIds.push(this.detailInfo.listQuery.agencyId)
            this.bizKeys.push(this.detailInfo.listQuery.bizKey)
        },
        // 工资明细页面退回
        financialDialogReject() {
            this.operateAgencyIds = []
            this.title1 = '退回说明'
            this.auditFormVisible = true
            this.operateCode = 'reject'
            const auditExplain = this.detailInfo.operateRows.auditExplain
            this.formData.auditExplain = auditExplain === null ? '不同意' : auditExplain.substring(auditExplain.indexOf('：') + 1)
            this.operateAgencyIds.push(this.detailInfo.listQuery.agencyId)
            this.bizKeys.push(this.detailInfo.listQuery.bizKey)
        },
        //模板导出
        exportTemplate() {
            Object.assign(this.listQuery, this.formData);
            this.listQuery["agencyId"] = this.detailInfo.listQuery.agencyId;
            outPutSalaryReportList(this.listQuery).then((response) => {
                const link = document.createElement("a");
                const objectUrl = URL.createObjectURL(response);
                link.href = objectUrl;
                link.download = "单位工资编报.xls";
                link.click();
                URL.revokeObjectURL(objectUrl);
            });
        },
        // 审核通过
        financialAuditPass() {

            // this.$confirm('确定审核吗?', '提示', {
            //   confirmButtonText: '确定',
            //   cancelButtonText: '取消',
            //   type: 'warning'
            // }).then(() => {
            this.formData['agencyIds'] = this.operateAgencyIds
            this.formData['bizKeys'] = this.bizKeys
            this.formData['menuid'] = this.$router.currentRoute.meta.menuid
            this.formData['menuname'] = this.$router.currentRoute.meta.menuname
            this.formData['params'] = this.$route.meta.pageUrl
            this.formData['isThirteen'] = this.listQuery.isThirteen

            if (this.listQuery.isThirteen === null || this.listQuery.isThirteen === '' || this.listQuery.isThirteen === undefined) {
                this.$message({
                    showClose: true,
                    message: '请选择批次',
                    type: 'warning',
                    duration: 4000

                })
                this.saveExplainLoading = false
                return

            }

            financialAuditPass(this.formData).then(response => {
                this.salaryFormVisible = false
                this.auditFormVisible = false

                this.$message({
                    showClose: true,
                    message: '审核成功',
                    type: 'success',
                    duration: 4000
                })

                this.saveExplainLoading = false
                this.handleQuery()
            }).catch(() => {
                this.saveExplainLoading = false
            })

        },
        // 退回
        financialAuditReject() {
            // this.$confirm('确定退回吗?', '提示', {
            //   confirmButtonText: '确定',
            //   cancelButtonText: '取消',
            //   type: 'warning'
            // }).then(() => {
            this.formData['agencyIds'] = this.operateAgencyIds
            this.formData['bizKeys'] = this.bizKeys
            this.formData['menuid'] = this.$router.currentRoute.meta.menuid
            this.formData['menuname'] = this.$router.currentRoute.meta.menuname
            this.formData['params'] = this.$route.meta.pageUrl
            this.formData['isThirteen'] = this.listQuery.isThirteen

            const selection = this.$refs.singalTable.selection
            if (this.listQuery.isThirteen === null || this.listQuery.isThirteen === '' || this.listQuery.isThirteen === undefined) {
                this.$message({
                    showClose: true,
                    message: '请选择批次',
                    type: 'warning',
                    duration: 4000

                })
                this.saveExplainLoading = false
                return

            }
            financialAuditReject(this.formData).then(response => {
                this.salaryFormVisible = false
                this.auditFormVisible = false

                this.$message({
                    showClose: true,
                    message: '退回成功',
                    type: 'success',
                    duration: 4000
                })

                this.saveExplainLoading = false
                this.handleQuery()

            }).catch(() => {
                this.saveExplainLoading = false
            })

            // })
        },
        // 撤销审核
        financialAuditRevoke() {
            this.operateAgencyIds = []
            const selection = this.$refs.singalTable.selection
            if (selection.length === 0) {
                this.$message({
                    message: '请选择要撤销审核的单位',
                    type: 'warning',
                    showClose: true,
                    duration: 4000
                })
                this.$emit('revokeCallback')
                return
            }
            selection.forEach(item => {
                this.operateAgencyIds.push(item.id)
                this.bizKeys.push(item.bizKey)
            })
            // 如果已经生成工资数据，则不可以撤销审核
            const param = { 'agencyIds': this.operateAgencyIds.join(','), "bizKeys": this.bizKeys.join(',') }
            getSalaryDataByAgencyId(param).then((response) => {
                // 已生成工资数据
                // if (response.data === true) {
                //   this.$message({
                //     showClose: true,
                //     message: '存在已生成工资数据的单位，不允许撤销审核',
                //     type: 'warning',
                //     duration: 4000
                //   })
                //   this.$emit('revokeCallback')
                // } else {
                // this.$confirm('确定撤销审核吗?', '提示', {
                //   confirmButtonText: '确定',
                //   cancelButtonText: '取消',
                //   type: 'warning'
                // }).then(() => {
                this.formData['agencyIds'] = this.operateAgencyIds
                this.formData['isThirteen'] = this.listQuery.isThirteen
                this.formData['bizKeys'] = this.bizKeys
                this.formData['menuid'] = this.$router.currentRoute.meta.menuid
                this.formData['menuname'] = this.$router.currentRoute.meta.menuname
                //  const selection = this.$refs.singalTable.selection
                if (this.listQuery.isThirteen === null || this.listQuery.isThirteen === '' || this.listQuery.isThirteen === undefined) {
                    this.$message({
                        showClose: true,
                        message: '请选择批次',
                        type: 'warning',
                        duration: 4000

                    })
                    this.$emit('revokeCallback')
                    return

                }
                financialAuditRevoke(this.formData).then(response => {
                    this.auditFormVisible = false
                    this.$message({
                        showClose: true,
                        message: '撤销审核成功',
                        type: 'success',
                        duration: 4000
                    })
                    this.$emit('revokeCallback')
                    this.handleQuery()
                }).catch(() => {
                    this.$emit('revokeCallback')
                })
                // })
                // }
            })
        },

        // ======================工资明细弹出页面方法===========================
        // 工资明细打开页面
        salaryDetail(row) {
            // console.log(row)
            this.detailInfo.operateRows = row
            this.operateAgencyIds = []
            this.salaryFormVisible = true
            this.detailInfo.listQuery.agencyId = row.id
            this.detailInfo.listQuery.isThirteen = row.isThirteen
            this.detailInfo.agencyName = row.agencyName
            this.detailInfo.listQuery.bizKey = row.bizKey
            this.detailInfo.queryForm.salaryType = ''
            this.detailInfo.list = []
            this.detailInfo.total = 0
            this.detailInfo.addNum = 0
            this.detailInfo.salaryChangeNum = 0
            this.initUnitSalaryBaseData()
            this.queryUnitAuditPage()
            // 获取新增人数
            this.getAddPersonNumByAgencyId()
            // 获取工资变动人数
            this.selectSalaryChangePersonNum()

        },
        // 查询工资明细
        queryUnitAuditPage() {
            this.detailInfo.listLoading = true
            Object.assign(this.detailInfo.listQuery, this.detailInfo.queryForm)
            this.initUnitSalaryBaseData()
            // 原方法与单位审核共用同一方法，现拆分为两个不同请求，区分单位编辑和上报

            queryFinancialAuditSalaryPage(this.detailInfo.listQuery).then(response => {
                // console.log(response)
                this.detailInfo.list = response.data.rows
                for (const item of this.detailInfo.list) {
                    if (item.children) {
                        // table中的row-key需要id不为空且不可重复
                        item.children[0].personId += 'noRepeat'
                    }
                }
                this.detailInfo.queryForm.personName = ''
                this.detailInfo.queryForm.idenNo = ''
                this.detailInfo.total = response.data.total
                this.detailInfo.listLoading = false
                this.selectIdentity = false

            })
            this.querySubmitReallySendSalarySumAndPersonTotal()
        },
        // 查询
        handleSalaryQuery() {
            this.detailInfo.listQuery.page = 1
            this.detailInfo.listQuery.limit = 200
            this.queryUnitAuditPage()

        },
        // 查询
        query() {
            // this.listQuery.changeAgency = changeAgency
            // this.listQuery.isThirteen = isThirteen
            this.getList()
        },
        // 初始化基础数据
        initUnitSalaryBaseData() {
            getSalaryType().then(response => {
                this.salaryTypes = Object.assign({}, response.data)
            })
            querySalaryNameDict(this.detailInfo.listQuery).then(res => {
                if (res.rscode === '100000') {
                    this.detailInfo.salaryNames = res.data
                } else {
                    this.detailInfo.salaryNames = []
                    this.$notify({
                        title: 'Error',
                        message: '获取字典失败',
                        type: 'error',
                        duration: 0
                    })
                }
            })
            // 查询部门名称
            getDepartmentList({ agencyId: this.detailInfo.listQuery.agencyId }).then(
                res => {
                    if (res.rscode === '100000') {
                        this.detailInfo.deptNames = res.data
                    } else {
                        this.detailInfo.deptNames = []
                        this.$notify({
                            title: 'Error',
                            message: '获取字典失败',
                            type: 'error',
                            duration: 0
                        })
                    }
                }
            )
            queryColumnName(this.detailInfo.listQuery).then(response => {
                if (response.rscode === '100000') {
                    this.detailInfo.columnNames = response.data
                } else {
                    this.detailInfo.columnNames = []
                    this.$notify({
                        title: 'Error',
                        message: '动态获取表头失败',
                        type: 'error',
                        duration: 0
                    })
                }
            })
        },
        // 查询总金额
        querySubmitReallySendSalarySumAndPersonTotal() {
            querySubmitReallySendSalarySumAndPersonTotal(this.detailInfo.listQuery.agencyId, this.detailInfo.listQuery.isThirteen, 1)
                .then(res => {
                    this.detailInfo.salaryMonth = res.data.salaryMonth
                    this.detailInfo.reallySendSalarySum = res.data.reallySendSalarySum
                    this.detailInfo.reallySendChangeSum = res.data.reallySendChangeSum
                    this.detailInfo.shouldSendChangeSum = res.data.shouldSendChangeSum
                    this.detailInfo.workSalarySum = res.data.workSalarySum
                    this.detailInfo.retireSalarySum = res.data.retireSalarySum
                    this.detailInfo.personTotal = res.data.personTotal
                    this.detailInfo.workTotal = res.data.workTotal
                    this.detailInfo.retireTotal = res.data.retireTotal
                    this.detailInfo.unitMinusTotal = res.data.unitMinusTotal
                    this.detailInfo.unitPlusTotal = res.data.unitPlusTotal
                    this.detailInfo.retireMinusTotal = res.data.retireMinusTotal
                    this.detailInfo.workMinusTotal = res.data.workMinusTotal
                    this.detailInfo.retirePlusTotal = res.data.retirePlusTotal
                    this.detailInfo.workPlusTotal = res.data.workPlusTotal
                    this.detailInfo.personUpdateTotal = res.data.personUpdateTotal
                })
                .catch(() => {
                    this.detailInfo.salaryMonth = ''
                    this.detailInfo.reallySendSalarySum = '0.00'
                    this.detailInfo.reallySendChangeSum = '0.00'
                    this.detailInfo.shouldSendChangeSum = '0.00'
                    this.detailInfo.workSalarySum = '0.00'
                    this.detailInfo.retireSalarySum = '0.00'
                    this.detailInfo.personTotal = '0'
                    this.detailInfo.workTotal = '0'
                    this.detailInfo.retireTotal = '0'
                    this.detailInfo.unitMinusTotal = '0'
                    this.detailInfo.unitPlusTotal = '0'
                    this.detailInfo.retireMinusTotal = '0'
                    this.detailInfo.workMinusTotal = '0'
                    this.detailInfo.retirePlusTotal = '0'
                    this.detailInfo.workPlusTotal = '0'
                    this.detailInfo.personUpdateTotal = '0'
                })
        },
        // 查询调入人员人数
        getAddPersonNumByAgencyId() {
            getAddPersonNumByAgencyId(this.detailInfo.listQuery).then(response => {
                this.detailInfo.addNum = response.data
            })
        },
        // 获取工资变动人数
        selectSalaryChangePersonNum() {
            selectSalaryChangePersonNum(this.detailInfo.listQuery).then(response => {
                this.detailInfo.salaryChangeNum = response.data
            })
        },
        // 附件方法
        appendixOpen() {
            const selection = this.$refs.singalSalaryTable.selection
            const idList = []
            selection.forEach(item => {
                idList.push({ id: item.personId })
            })
            this.$refs.enc.appendixOpen(idList, false, undefined, this.detailInfo.listQuery.agencyId)
        },
        // 查看详情
        viewInfo(currenRow) {
            const personId = currenRow.personId.replace('noRepeat', '')
            const agencyId = currenRow.agencyId
            this.$refs.PersonSalaryInfoVerify.viewInfo(personId, '1', agencyId)
        },
        // 人事变动情况查询
        getPersonChange() {
            this.$refs.personChangeInfo.getPersonChange(this.detailInfo.listQuery.agencyId)
        },
        // 查询姓名身份证弹框
        changeIdDialogStatus() {
            this.selectIdentity = true

        },
        // 获取勾选的数据data
        handleSelectionChange(val) {
            this.selected_list = val;

        },
        //自定义合计
        getSummaries(param) {
            const { columns, data } = param;
            const sums = [];
            columns.forEach((column, index) => {
                if (index === 2) {
                    sums[index] = '合计';
                    return;
                }
                if (index < 7) {
                    return;
                }
                if (this.tabPane === 'all' && index < 8) {
                    return;
                }
                // console.log(index)
                let values;
                values = data.map(item => Number(item[column.property])); // 无勾选
                if (this.selected_list && this.selected_list.length > 0) { // 有勾选
                    values = this.selected_list.map(item => Number(item[column.property]));
                }
                if (!values.every(value => isNaN(value))) {
                    sums[index] = values.reduce((prev, curr) => {
                        const value = Number(curr);
                        if (!isNaN(value)) {
                            return prev + curr;
                        } else {
                            return prev;
                        }
                    }, 0);

                    if ((this.tabPane != 'all' && index != 6 && index != 7 && index != 8 && index != 9)) {
                        sums[index] = Number(sums[index]).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,")
                        sums[index] += ' 元';
                    } else if ((this.tabPane === 'all' && index != 7 && index != 8 && index != 9)) {
                        sums[index] = Number(sums[index]).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,")
                        sums[index] += ' 元';
                    } else {
                        sums[index] += ' 人';
                    }

                } else {
                    sums[index] = 'N/A';
                }
            });

            return sums;
        }
    }
}
</script>
<style lang="scss" scoped>
.el-dialog {
    margin-top: 0 !important;
}

// ::v-deep tbody > tr:nth-child(1) {
//   .el-checkbox {
//     display: none;
//   }
// }
// 滚动条的宽度
// ::v-deep .el-table__body-wrapper .is-scrolling-left::-webkit-scrollbar {
//   width: 16px; // 横向滚动条
//   height: 16px; // 纵向滚动条 必写
// }
// // 滚动条的滑块
// ::v-deep .el-table__body-wrapper .is-scrolling-left::-webkit-scrollbar-thumb {
//   background-color: rgb(121, 118, 118);
//   border-radius: 3px;
// }
.el-table--scrollable-x .el-table__body-wrapper {
    height: 51px;
}

.scroll {
    width: 30%;
    white-space: nowrap;
    overflow: scroll;
    overflow-y: auto;
    display: inline-block;

    .el-row {
        width: 660px;
        height: 44px;
        background: #f9f9f9;

        .el-col {
            height: 100%;

            .el-left {
                text-align: left;
                margin-top: 8px;
                margin-left: 10px;
            }

            .el-center {
                text-align: center;
                margin-top: 4px;
            }

            .el-right {
                text-align: right;
                margin-top: 6px;

                button {
                    width: 32px;
                    height: 32px;
                    padding: 8px;
                }

                .minus-button {
                    margin-right: 56px;
                }
            }
        }
    }

    .table-wrapper {
        width: 660px;
    }
}

.el-form-item {
    margin-bottom: 0;
}

::v-deep.el-table {
    .cell {

        // .el-table__expand-icon {
        //   display: none;
        // }
        .el-table__indent {
            padding-left: 0 !important;
        }

        .el-table__placeholder {
            display: none;
        }
    }
}

.addForm {
    text-align: center;

    .selectSpan {
        margin-right: 40%;
        font-size: 18px;
        font-weight: 500;
    }

    .addSelectRow {
        margin-top: 3%;
    }

    .addButRow {
        margin-top: 5%;
    }

    .addTitpsRow {
        margin-top: 8%;
        margin-bottom: 8%;

        .addTitps {
            font-size: 18px;
            color: #ff0000;
            font-weight: 600;
        }
    }
}

::v-deep .salaryTable {
    .el-table__row--level-1 {
        .el-table-column--selection {
            .el-checkbox__input {
                display: none;
            }
        }
    }
}

.filter-container {
    padding-bottom: 0px;
}
</style>
